package cn.edu.cqu.bysj.controllers.sortTrains;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import cn.edu.cqu.bysj.domains.QueryLeftNewDTO;

public class PriceAsceSort implements SortStrategy {

	@Override
	public List<QueryLeftNewDTO> sort(List<QueryLeftNewDTO> trains) {
		class PriceCompartor implements Comparator<QueryLeftNewDTO>
		{
			@Override
			public int compare(QueryLeftNewDTO o1, QueryLeftNewDTO o2)
			{
				float condition = o1.getPrice() - o2.getPrice();
				if (condition > 0)
				{
					return 1;
				} else if (condition < 0)
				{
					return -1;
				}else
				{
					return 0;
				}
			}
		};
		PriceCompartor priceCompartor = new PriceCompartor();
		Collections.sort(trains,priceCompartor);
		return trains;
	}

}
